package com.kaigejava.juc.lock.ReadWriteLock;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author kaigejava
 * 公示屏对象
 */
public class Screen {

    //屏幕
    private Map<String,Object> screenMap = new HashMap<>();
    private  void intScreen(){
        screenMap.put("G505","正常");
    }

    /**
     * 更新屏幕信息
     */
    public void writeMsg(String key,Object value){
        intScreen();
        System.out.println("当前更新屏幕信息的工作人员的工号是:"+Thread.currentThread().getId()+"更新的数据是:"+key+"车次"+value);
        try {
            TimeUnit.MICROSECONDS.sleep(300);
            screenMap.put(key,value);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("工号为:"+Thread.currentThread().getId()+"更新"+key+"车次数据操作完成======");
    }

    /**
     * 从屏幕中获取获取信息
     */
    public void ReadMsg(String key){
        intScreen();
        System.out.println(Thread.currentThread().getId()+"正在查看"+key+"车次信息");
        Object value= null;
        try {
            TimeUnit.MICROSECONDS.sleep(300);
            value =   screenMap.get(key);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getId()+"查看"+key+"车次信息完成。=====。获取到信息:"+value);
    }
}
